package sort;

import com.gule.gl.leetcode.editor.cn.definition.ListNode;

import java.util.Objects;

/**
 * @Author: Hugh
 * @Date: 2021/3/10
 */
public class Test {
    public static void main(String[] args) {


    }

    // A->B->C->D
    public ListNode revert(ListNode head){
        if(Objects.isNull(head)){
            return head;
        }
        ListNode pre = null;
        ListNode cur = head;
        ListNode next = head;
        while (Objects.nonNull(cur)){
            next = cur.next;
            //交换指针
            cur.next = pre;
            //循环赋值
            pre = cur;
            cur = next;
        }
        return pre;
    }
    public ListNode revertFromMToN(ListNode head, int m, int n){
        ListNode cur = head;
        ListNode next = head;
        ListNode pre = null;
        int index = 1;
        while (Objects.nonNull(cur)){
            next = cur.next;
            pre = cur;
            cur = next;
            if(index==m){
                while (index<=n){
                    next = cur.next;
                    cur.next = pre;
                    //循环赋值
                    pre = cur;
                    cur = next;
                    index++;
                }
                break;
            }
            index++;
        }
        return head;
    }
}
